//
//  SocketUtil.hpp
//  MultiPlayer
//
//  Created by 星落之尘 on 2020/6/9.
//  Copyright © 2020 Tan. All rights reserved.
//


#include <stdio.h>
#include "RoboCatPch.h"

enum SocketAddressFamily
{
    INET = AF_INET,
    INET6 = AF_INET6
};

class SocketUtil {
public:
    static bool StaticInit();
    static void CleanUp();
    
    
    static void ReportError(const char* inOperationDesc);
    static int GetLastError();
    
    static int Select(const vector<TCPSocketPtr>* inReadSet,
                      vector<TCPSocketPtr>* outReadSet,
                      const vector<TCPSocketPtr>* inWirteSet,
                      const  vector<TCPSocketPtr>* outWriteSet,
                      const vector<TCPSocketPtr>* inExceptSet,
                      vector<TCPSocketPtr>* outExceptSet);
    
    static UDPSocketPtr CreateUDPSocket( SocketAddressFamily inFamily);
    static TCPSocketPtr CreateTCPSocket( SocketAddressFamily inFamily);

private:
    inline static fd_set* FillSetFromVector(fd_set& outSet, const vector<TCPSocketPtr>* inSockets, int& ioNaxNfds);
    inline static void FillVectorFromSet(vector<TCPSocket>* outSockets, const vector<TCPSocket>* inSockets, const fd_set& inSet);
    
};

